import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ChatRecordSettingsPage extends StatefulWidget {
  const ChatRecordSettingsPage({super.key});

  @override
  State<ChatRecordSettingsPage> createState() => _ChatRecordSettingsPageState();
}

class _ChatRecordSettingsPageState extends State<ChatRecordSettingsPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BrnAppBar(title: '清除记录', backgroundColor: Colors.white),
        backgroundColor: const Color(0xFFF6F6F6),
        body: Column(
          children: [
            _buildItem(
                title: '清理消息记录',
                isShowLine: true,
                action: () {
                  SmartDialog.show(
                    usePenetrate: false,
                    clickMaskDismiss: true,
                    backType: SmartBackType.block,
                    keepSingle: true,
                    useAnimation: false,
                    builder: (context) => Center(
                      child: CustomAlertWidget(
                        title: '温馨提示',
                        content: "确认删除并清除聊天记录？\n",
                        confirmText: '确定',
                        confirmAction: () {},
                        cancemText: '取消',
                      ),
                    ),
                  );
                }),
            _buildItem(
                title: '清理喵塘列表',
                action: () {
                  SmartDialog.show(
                    usePenetrate: false,
                    clickMaskDismiss: true,
                    backType: SmartBackType.block,
                    keepSingle: true,
                    useAnimation: false,
                    builder: (context) => Center(
                      child: CustomAlertWidget(
                        title: '温馨提示',
                        content: "确认要清除喵塘列表吗？\n",
                        confirmText: '确定',
                        confirmAction: () {},
                        cancemText: '取消',
                      ),
                    ),
                  );
                }),
          ],
        ));
  }

  Widget _buildItem({required String title, Function? action, bool isShowLine = false}) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        action?.call();
      },
      child: Container(
        color: title.isNotEmpty ? Colors.white : Colors.transparent,
        padding: EdgeInsets.symmetric(horizontal: 15.w),
        child: title.isNotEmpty
            ? Column(
                children: [
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: 15),
                    child: Row(
                      children: [
                        Text('${title.tr}  ',
                            style: TextStyle(fontSize: 15.sp, color: Colors.black, fontWeight: FontWeight.w500)),
                        const Spacer(),
                        const Icon(Icons.navigate_next_sharp, size: 25, color: Color(0xFF000000)),
                      ],
                    ),
                  ),
                  if (isShowLine) const Divider(color: Color(0xFFEEEEEE), height: 0.5)
                ],
              )
            : const SizedBox(height: 10),
      ),
    );
  }
}
